/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */

package app.models.vote;

import com.github.sog.annotation.TableBind;
import com.github.sog.kit.date.DateProvider;
import com.github.sog.plugin.sqlinxml.SqlKit;
import com.jfinal.plugin.activerecord.Model;

/**
 * <p>
 * .
 * </p>
 *
 * @author sagyf yang
 * @version 1.0 2014-05-17 13:03
 * @since JDK 1.6
 */
@TableBind(tableName = "ol_vote_set_join")
public class VoteSetJoin extends Model<VoteSetJoin> {
    /**
     * The public dao.
     */
    public static final VoteSetJoin dao = new VoteSetJoin();

    public void join(long vote_set, long member, String choose_item) {
        final VoteSetJoin join = new VoteSetJoin();
        join.set("vote_set", vote_set);
        join.set("member", member);
        join.set("join_time", DateProvider.DEFAULT.getCurrentDate());
        join.set("choose_item", choose_item);
        join.save();
    }


    public boolean checkJoinByMember(long member, long vote_set) {
        final VoteSetJoin join = findFirst(SqlKit.sql("voteset.checkJoinByMember"), member, vote_set);
        return join != null && (join.getNumber("cout").intValue() > 0);
    }
}